package com.ruoyi.ewem.controller;

import cn.hutool.json.JSONObject;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.ewem.domain.Pie;
import com.ruoyi.ewem.domain.Product;
import com.ruoyi.ewem.domain.User;
import com.ruoyi.ewem.service.ProductService;
import com.ruoyi.ewem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Yanyanyu
 * @Date: 2024/7/25 19:45
 */
@RestController
@RequestMapping("screen")
public class ScreenController {

    @Autowired
    private ProductService productService;

    @RequestMapping("countUser")
    public AjaxResult countUser(){
        List<Pie> pie = new ArrayList<>();
        pie.add(new Pie("在线",38));
        pie.add(new Pie("离线",46));
        for (Pie p : pie) {
            p.setValue(p.getValue()+ (int)(Math.random() * 5 + 1));
        }
        return AjaxResult.success(pie);
    }

 /*   @RequestMapping("countProduct")
    public AjaxResult countProduct(){
        List<Product> list=productService.getNum();
        return AjaxResult.success(list);
    }*/


    @RequestMapping("countProduct")
    public Map<String, Object> countProduct(){
        List<Product> list=productService.getNum();
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> typeNameList = new ArrayList<>();
        ArrayList<Integer> numList = new ArrayList<>();
        for (Product product : list) {
            typeNameList.add(product.getTypeName());
            numList.add(product.getNum());
        }
        map.put("typeName",typeNameList);
        map.put("num",numList);
        return map;
    }

}
